import React from 'react'
import H2 from './02_H2'
import Button from './03_Button'
import { add, sub } from '../../app/slices/zanSlice'
import uuid from 'uuid';
import {nanoid} from 'nanoid';
import { add as insert, remove } from '../../app/slices/userSlice'
import { useDispatch, useSelector } from 'react-redux';
export default function ReduxCom() {
  //获取 dispatch 函数
  let dispatch = useDispatch();
  //获取状态
  let zan = useSelector(state => state.zan);

  return (
    <>
      <H2 />
      <Button/>
      <hr />
      <h2>{zan}</h2>
      <button onClick={() => {
        //更新状态
        dispatch(add(1));
      }}>新增</button>
      <button onClick={() => {
        dispatch(sub(1));
      }}>减少</button>
    </>
  )
}
